<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<c:set var="loanStatus">${loanVO.loan.loanStatus}</c:set>
<c:set var="loanStatusStr">${applicationScope.loanStatusMap.get(loanStatus)}</c:set>
<div class="bjui-pageContent">

    <div>
        <h1 align="center">
            标的详情
        </h1>
    </div>

    <div data-layout-h="0" class="bjui-row col-3">
        <label class="row-label">标的名称:</label>
        <div class="row-input">
            ${loanVO.loan.fullName}
        </div>

        <label class="row-label">借款期限:</label>
        <div class="row-input">
            ${loanVO.loan.loanTime}天
        </div>

        <label class="row-label">年利率:</label>
        <div class="row-input">
            ${loanVO.loan.rateD}%
        </div>

        <label class="row-label">标的状态:</label>
        <div class="row-input">
            ${loanStatusStr}
        </div>

        <label class="row-label">融资金额:</label>
        <div class="row-input">
            ${loanVO.loan.currentAmountD}元
        </div>
    </div>

    <ul class="nav nav-tabs" role="tablist">
        <li class="active"><a href="#detail${loanVO.loan.loanId}" role="tab" data-toggle="tab">详细信息</a></li>
        <%--<li class=""><a href="/admin/loan/loan/ajax/all" role="tab" data-toggle="ajaxtab" data-target="#profile"--%>
        <%--data-reload="false">ajax加载</a></li>--%>
        <li class=""><a href="#buy${loanVO.loan.loanId}" role="tab" data-toggle="tab">投标记录</a></li>
        <li class="">
            <a href="/admin/loan/repay/repay?loanId=${loanVO.loan.loanId}&isInfo=true"
               role="tab" data-toggle="ajaxtab" data-target="#repay${loanVO.loan.loanId}" data-reload="false">
                还款记录
            </a>
        </li>
    </ul>

    <div class="tab-content">
        <div class="tab-pane fade active in" id="detail${loanVO.loan.loanId}">
            <div data-layout-h="0" class="bjui-row col-2">

                <label class="row-label">简短名称:</label>
                <div class="row-input">
                    ${loanVO.loan.shortName}
                </div>

                <label class="row-label">借款用户:</label>
                <div class="row-input">
                    <a href="javascript:userInfo('${loanVO.loanUser.id}','${loanVO.loanUser.userName}')">
                        ${loanVO.loanUser.userName}
                    </a>
                </div>

                <label class="row-label">最低投标金额:</label>
                <div class="row-input">
                    ${loanVO.loan.minAmountD}元
                </div>

                <label class="row-label">最高投标金额:</label>
                <div class="row-input">
                    ${loanVO.loan.maxAmountD}元
                </div>

                <label class="row-label">筹标期限:</label>
                <div class="row-input">
                    ${loanVO.loan.allottedTime}天
                </div>

                <label class="row-label">还款方式:</label>
                <div class="row-input">
                    一次性还清
                </div>

                <label class="row-label">提前还款违约:</label>
                <div class="row-input">
                    ${loanVO.loanInfo.compensateD}%
                </div>

                <label class="row-label">逾期罚息:</label>
                <div class="row-input">
                    ${loanVO.loan.arrearsOverRateD}%
                </div>

                <label class="row-label">违约金获得:</label>
                <div class="row-input">
                    <c:if test="${loanVO.loan.compensateMoneyGiveCompany}">
                        公司
                    </c:if>
                    <c:if test="${!loanVO.loan.compensateMoneyGiveCompany}">
                        用户
                    </c:if>
                </div>

                <label class="row-label">逾期罚息获得:</label>
                <div class="row-input">
                    <c:if test="${loanVO.loan.overMoneyGiveCompany}">
                        公司
                    </c:if>
                    <c:if test="${!loanVO.loan.overMoneyGiveCompany}">
                        用户
                    </c:if>
                </div>

                <label class="row-label">标的描述:</label>
                <div class="row-input">
                    ${loanVO.loan.loanDesc}
                </div>

                <label class="row-label"></label>
                <div class="row-input">
                </div>

                <label class="row-label">抵押物图片:</label>
                <div class="row-input">
                    <div class="loanPawnPic"></div>
                </div>
            </div>
        </div>
        <div class="tab-pane fade" id="buy${loanVO.loan.loanId}">
            <table class="table table-bordered" style="width: 100%;">
                <thead>
                <tr>
                    <td>投资人</td>
                    <td>借款人</td>
                    <td>已投金额</td>
                    <td>预收益</td>
                    <td>应回款</td>
                    <td>投资时间</td>
                </tr>
                </thead>
                <tbody>
                <c:set value="0" var="buyMoneyD_sum"/>
                <c:set value="0" var="shouldRepayMoneyD_sum"/>
                <c:forEach items="${loanVO.repayUserPaging.list}" var="repayUser">
                    <tr>
                        <td>
                            <a href="javascript:userInfo('${repayUser.userId}','${repayUser.userName}')">${repayUser.userName}</a>
                        </td>
                        <td>
                            <a href="javascript:userInfo('${repayUser.loanUserId}','${repayUser.loanUserName}')">${repayUser.loanUserName}</a>
                        </td>
                        <td>
                                ${repayUser.buyMoneyD}
                        </td>
                        <td>
                            <fmt:formatNumber pattern="####0.00" value="${repayUser.shouldRepayMoneyD - repayUser.buyMoneyD}"/>
                        </td>
                        <td>
                                ${repayUser.shouldRepayMoneyD}
                        </td>
                        <td>
                            <fmt:formatDate value="${repayUser.buyDate}" pattern="yyyy-MM-dd HH:mm:ss"/>
                        </td>
                    </tr>
                    <c:set value="${buyMoneyD_sum+repayUser.buyMoneyD}" var="buyMoneyD_sum"/>
                    <c:set value="${shouldRepayMoneyD_sum+repayUser.shouldRepayMoneyD}" var="shouldRepayMoneyD_sum"/>
                </c:forEach>
                </tbody>
                <tfoot>
                <tr>
                    <td>合计:</td>
                    <td></td>
                    <td>
                        <fmt:formatNumber pattern="####0.00" value="${buyMoneyD_sum}"/></td>
                    <td>
                        <fmt:formatNumber pattern="####0.00" value="${shouldRepayMoneyD_sum-buyMoneyD_sum}"/></td>
                    <td>
                        <fmt:formatNumber pattern="####0.00" value="${shouldRepayMoneyD_sum}"/></td>
                    <td></td>
                </tr>
                </tfoot>
            </table>
        </div>
        <div class="tab-pane fade" id="repay${loanVO.loan.loanId}"></div>
    </div>
</div>
<script type="text/javascript">
    $(function () {
        var pawnPic = '${loanVO.loan.pawnPic}';
        pawnPic = pawnPic.replaceAll("sep#!", "\\\\");
        var pawnPicS = pawnPic.split("()");
        var pawnPicImageHtml = "";
        for (var i = 0; i < pawnPicS.length; i++) {
            var onePawnPic = pawnPicS[i];
            if (onePawnPic !== "") {
                pawnPicImageHtml += imgText2html(onePawnPic);
            }
        }
        $.CurrentDialog.find(".loanPawnPic").html(pawnPicImageHtml);
    });

    function imgText2html(imageStr) {
        return "<img width='100%' src='/tool/readFile?path=" + imageStr + "'>";
    }
</script>